﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BarCode.Common;
using BarCode.Module;

namespace BarCode.Forms
{
    public partial class Select : Form
    {
        public Select()
        {
            InitializeComponent();
        }

        private void btnDZ_Click(object sender, EventArgs e)
        {
            GlobalVal.PRE_TBL_NAME = "";
            GlobalVal.PRE_FIELD = "";
            GlobalVal.CUR_TBL_NAME = Consts.DZ_TBL_NAME;
            GlobalVal.CUR_FIELD = Consts.DZ_FIELD;
            DZBarCode objForm = new DZBarCode();
            this.Hide();
            objForm.ShowDialog();
            this.Show();
        }

        private void btnZKB_Click(object sender, EventArgs e)
        {
            GlobalVal.PRE_TBL_NAME = Consts.DZ_TBL_NAME;
            GlobalVal.PRE_FIELD = Consts.DZ_FIELD;
            GlobalVal.CUR_TBL_NAME = Consts.ZKB_TBL_NAME;
            GlobalVal.CUR_FIELD = Consts.ZKB_FIELD;

            ZKBBarCode objForm = new ZKBBarCode();
            this.Hide();
            objForm.ShowDialog();
            this.Show();
        }

        private void btnMP_Click(object sender, EventArgs e)
        {
            //GlobalVal.PRE_TBL_NAME = Consts.ZKB_TBL_NAME;
            //GlobalVal.PRE_FIELD = Consts.ZKB_FIELD;
            GlobalVal.CUR_TBL_NAME = Consts.MP_TBL_NAME;
            GlobalVal.CUR_FIELD = Consts.MP_FIELD;

            TMZBarCode objForm = new TMZBarCode();
            this.Hide();
            objForm.ShowDialog();
            this.Show();
        }

        private void btnSG_Click(object sender, EventArgs e)
        {
            //GlobalVal.PRE_TBL_NAME = Consts.MP_TBL_NAME;
            //GlobalVal.PRE_FIELD = Consts.MP_FIELD;
            //GlobalVal.CUR_TBL_NAME = Consts.SG_TBL_NAME;
            //GlobalVal.CUR_FIELD = Consts.SG_FIELD;
            GlobalVal.PRE_TBL_NAME = Consts.ZKB_TBL_NAME;
            GlobalVal.PRE_FIELD = Consts.ZKB_FIELD;
            GlobalVal.CUR_TBL_NAME = Consts.MP_TBL_NAME;
            GlobalVal.CUR_FIELD = Consts.MP_FIELD;


            SGBarCode objForm = new SGBarCode();
            this.Hide();
            objForm.ShowDialog();
            this.Show();

        }

        private void Select_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void btnScan_Click(object sender, EventArgs e)
        {
            GlobalVal.PRE_TBL_NAME = Consts.ZKB_TBL_NAME;
            GlobalVal.PRE_FIELD = Consts.ZKB_FIELD;
            GlobalVal.CUR_TBL_NAME = Consts.MP_TBL_NAME;
            GlobalVal.CUR_FIELD = Consts.MP_FIELD;

            GasMain objForm = new GasMain();
            this.Hide();
            objForm.ShowDialog();
            this.Show();
        }

        private void Select_Load(object sender, EventArgs e)
        {

            GlobalVal.stationNo = IniFileHelper.getStringValue("System", "Work_Station");
            if (string.IsNullOrEmpty(GlobalVal.stationNo))
            {
                MessageUtil.Error("工位号未设置，请设置后重启程序。");
                Application.Exit();
            }

            String monitorFlag = IniFileHelper.getStringValue("System", "Monitor_Flag");
            if ("1".Equals(monitorFlag))
            {
                bool loadRet = ComUtil.LoadMonitor(GlobalVal.ComDevice);
                if (!loadRet)
                {
                    MessageUtil.Error("监视器无法连接，请设置正确串口后重启程序。");
                    Application.Exit();
                }
            }
        }

        
    }
}
